package 集合.日常使用;

import cn.hutool.core.collection.CollUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * Description
 *
 * @Author: SunAo
 * @Date: 2022/3/17 11:01
 */
public class 集合排序 {

    @Test
    public void test(){
        List<Person> list = Arrays.asList(
                new Person("SunAo", 1000),
                new Person("SunAo", 1),
                new Person("SunAo", 0),
                new Person("SunAo", 12)
        );
        CollUtil.sort(list,(p1,p2)->{
            if(p1.age > p2.age){
                return 1;
            }else{
                return -1;
            }
        });

        list.stream().forEach(System.out::println);
    }

    @Data
    @ToString
    @AllArgsConstructor
    public static class Person{
        public String name;
        public Integer age;
    }
}
